﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NeuralNetworkComponents
{
    public abstract class Layer
    {
        public Int32 InputsCount { get; protected set; }
        public Int32 NeuronsCount { get; protected set; }
        public Neuron[] Neurons { get; protected set; }
        public Double[] Output { get; protected set; }

        public Neuron this[int index]
        {
            get { return Neurons[index]; }
        }

        protected Layer(int neuronsCount, int inputsCount)
        {
            this.InputsCount = Math.Max(1, inputsCount);
            this.NeuronsCount = Math.Max(1, neuronsCount);
            Neurons = new Neuron[this.NeuronsCount];
            Output = new Double[this.NeuronsCount];
        }

        public virtual Double[] Compute(Double[] input)
        {
            for (int i = 0; i < NeuronsCount; i++)
                Output[i] = Neurons[i].Compute(input);

            return Output;
        }

        public virtual void Randomize()
        {
            foreach (Neuron neuron in Neurons)
                neuron.Randomize();
        }
    }
}
